home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / DataCopy / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.0 KB  |  178 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"            // CPizzaCommand
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWEVENTU_H
  31. #include "FWEventU.h"            // FW_IsCommandKeyPressed
  32. #endif
  33.  
  34. #include "FWClpCmd.h"            // FW_CClipboardCommand
  35.  
  36. #include "FWDrCmd.h"            // FW_CDragCommand, FW_CDropCommand
  37.  
  38. // ----- OS Layer -----
  39. #ifndef FWCFMRES_H
  40. #include "FWCFMRes.h"            // FW_CSharedLibraryResourceFile, FW_gInstance
  41. #endif
  42.  
  43. #ifndef FWMENU_H
  44. #include "FWMenu.h"                // FW_CMenuBar, etc.
  45. #endif
  46.  
  47. #ifndef FWEVENT_H
  48. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  49. #endif
  50.  
  51. #ifndef FWRECSHP_H
  52. #include "FWRecShp.h"            // FW_CRectShape
  53. #endif
  54.  
  55. #ifndef FWPICSHP_H
  56. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  57. #endif
  58.  
  59. #ifndef FWRRCSHP_H
  60. #include "FWRRcShp.h"            // FW_CRoundRectShape
  61. #endif
  62.  
  63. #ifndef FWCMD_H
  64. #include "FWCmd.h"                // FW_CCommand
  65. #endif
  66.  
  67. #include "ShapeB.xh"
  68.  
  69. //========================================================================================
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment DataCopy
  72. #endif
  73.  
  74. FW_DEFINE_AUTO(CDataCopyFrame)
  75.  
  76. //========================================================================================
  77. CDataCopyFrame::CDataCopyFrame(Environment* ev, ODFrame* odFrame, 
  78.                                     FW_CPresentation* presentation, CDataCopyContent* content)
  79.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  80.     FW_MDraggableFrame(ev, this),
  81.     FW_MDroppableFrame(ev, this),
  82.     fDataCopyContent(content)
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. CDataCopyFrame::~CDataCopyFrame()
  88. {
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. FW_Boolean 
  93. CDataCopyFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  94. {    
  95.     FW_UNUSED(ev);
  96.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  97.     this->GetContentView(ev)->FrameToViewContent(ev, where);    
  98.     if (theMouseEvent.IsCopyModifier(ev)) {
  99.         this->Drag(ev, theMouseEvent);
  100.         }
  101.     else {
  102.         CPizzaCommand* cmd = FW_NEW(CPizzaCommand, (ev, cMakePizzaCmd, this, 
  103.                                                 fDataCopyContent, where) );
  104.         cmd->Execute(ev);
  105.         }
  106.     return true;
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. void 
  111. CDataCopyFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  112. {
  113.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  114.     FW_CRect invalidRect = FW_GetShapeBoundingBox(ev, invalidShape);
  115. //    FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kRGBLightGray);
  116.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  117.     
  118.     // draw pizzas
  119.     CPizzaCollection* list = fDataCopyContent->MyGetPizzaList();
  120.     CPizzaCollectionIterator iter(list);
  121.     CPizza* pizza = NULL;
  122.     ODShape* shape = NULL;
  123.     for (pizza = (CPizza*) iter.First(); iter.IsNotComplete(); pizza = (CPizza*) iter.Next()) {
  124.         if (::FW_IsCommandKeyPressed()) {
  125.             FW_CAcquiredODShape rectShape = ::FW_NewODShape(ev, pizza->GetBounds());
  126.             shape = rectShape->Intersect(ev, invalidShape);
  127.             if ( ! shape->IsEmpty(ev) ) 
  128.                 pizza->Draw(context);
  129.             }
  130.         else 
  131.             if (invalidRect.IsIntersecting( pizza->GetBounds() ) )
  132.                 pizza->Draw(context);
  133.         }
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. FW_CClipboardCommand* 
  138. CDataCopyFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  139. {
  140.     return FW_NEW(FW_CClipboardCommand, 
  141.             (ev, commandID, this, ! FW_kCanUndo) );
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. FW_Boolean 
  146. CDataCopyFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  147.                                                     FW_Boolean isRoot)    // Override
  148. {
  149.     if (hasMenuFocus) {
  150.         FW_Boolean hasRightProperty = false;
  151.         ODType dataType = fDataCopyContent->GetPart(ev)->GetPartKind(ev);
  152.         hasRightProperty = this->HasPropertyOnClipboard(ev, kODPropContents, dataType);
  153.         menuBar->EnableCommand(ev, kODCommandPaste, hasRightProperty);
  154.     }
  155.     return false;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. FW_CDropCommand* 
  160. CDataCopyFrame::NewDropCommand(Environment *ev, 
  161.                                     FW_CFrame* frame,
  162.                                     ODDragItemIterator* dropInfo, 
  163.                                     ODFacet* facet, 
  164.                                     const FW_CPoint& dropPoint)
  165. {
  166.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, !FW_kCanUndo) );
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. FW_CDragCommand* 
  171. CDataCopyFrame::NewDragCommand(Environment *ev, 
  172.                                     FW_CFrame* theFrame, 
  173.                                     const FW_CMouseEvent& theMouseEvent)
  174. {
  175.     return FW_NEW(FW_CDragCommand, (ev, this, !FW_kCanUndo));
  176. }
  177.  
  178.